#include <iostream>
#include <vector>
using namespace std;

int n; //共计N个数
vector<string> name;
int order[20];//记录当前的排列顺序
bool chosen[20];
void calc(int k)
{
    if (k == n + 1)
    {
        for (int i = 1; i <= n; i++)
            cout << name[order[i] - 1] << " ";

        puts("");

        return;
    }
    for (int i = 1; i <= n; i++)
    {
        if (chosen[i])
            continue;
        order[k] = i;
        chosen[i] = 1;
        calc(k + 1);
        chosen[i] = 0;
        order[k] = 0;
    }
}

int main()
{

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        name.push_back(s);
    }
    calc(1);//k从1开始
}